package com.lj.back.manage.scaffold.common.convert;

import com.fasterxml.jackson.databind.introspect.Annotated;
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
import com.lj.back.manage.scaffold.common.annotation.convert.EnumConvert;
import com.lj.back.manage.scaffold.common.response.Response;

/**
 * 枚举json转换
 * @author lv
 * @version 1.0.0
 */
public class EnumConvertAnnotationIntrospector extends JacksonAnnotationIntrospector {

    private static final long serialVersionUID = 1L;

    @Override
    public Object findSerializer(Annotated annotated) {
        EnumConvert enumConvert = annotated.getAnnotation(EnumConvert.class);
        if (enumConvert != null){
            Class<? extends Enum<? extends Response>> value = enumConvert.value();
            return new EnumConvertJsonSerializer(value);
        }
        return super.findSerializer(annotated);
    }
}
